<template>
	<view class="Menu">
		<!-- 导航条 :style="{ height: $wanlshop.wanlsys().height + 'px' }"-->
		<view class="cu-custom">
			<view class="cu-bar fixed" style="background: #06224b; color: #fff;"
				:style="{height: $wanlshop.wanlsys().height + 'px',paddingTop: $wanlshop.wanlsys().top + 'px',}">
				<view class="action">
					<text class="wlIcon-fanhui1" style="margin-left: 0" @tap="$wanlshop.back(1)"></text>
				</view>
				<view class="content" :style="{ top: $wanlshop.wanlsys().top + 'px' }">
					智能交易策略终端
				</view>
				<view class="action" @tap="$wanlshop.auth('/pages/manage/order?id='+list.id)">
					<!-- {{$t('otcTransaction.but.my-order')}} -->
				</view>
			</view>
		</view>
		<view
			style="position: fixed;height: auto;  width: auto; top: 0; left: 0; bottom: 0; right: 0; padding-bottom: 80rpx;"
			:style="{top: $wanlshop.wanlsys().height + 'px',}">

			<view class="yldList">
				<view>
					<h3>{{list.money}} <span>起投</span></h3>
				</view>
				<view>合约到期：<span>{{list.endtime}}</span></view>
				<view>月化：<span>{{list.rate+'%'}}</span></view>
				<view class="btn" @tap="$wanlshop.auth('/pages/manage/details?id='+list.id)">查看产品详情</view>
				<view class="yldfot">
					<view class="yldfotL">YLD数量：<span>{{ap_Yld}}</span></view>
					<view class="yldfotR">
						<view class="btn btn1" @click="financing(list)">理财</view>
						<view class="btn btn2" @tap="$wanlshop.auth('/pages/newPage/stock4')">详情</view>
					</view>
				</view>
				<view class="line"></view>
				<view class="yldfot" v-for="(item,index) in data" :key="index">
					<view class="yldfotL">YLD数量：<span>{{item.money}}</span></view>
					<view class="yldfotR">
						<view class="btn btn1" @click="zhuanz(item)" v-if="item.type!==0">转账</view>
						<view class="btn btn1" @click="fout(item)" v-if="item.type!==0">复投</view>
						<view class="btn btn2" @tap="$wanlshop.auth('/pages/manage/order?id='+item.id)">详情</view>
					</view>
				</view>
			</view>

		</view>
		<u-popup :show="show" mode="bottom" @close="close" :closeable='true' :closeOnClickOverlay='true'>
			<view class="cont">
				<view class="title">转账</view>
				<view class="cent">
					<view class="formList">
						<h1>资产:<span>YLD</span></h1>
						<view class="list">
							<u--input border='none' v-model="Inputmoney" placeholder="请输入资产"></u--input>
						</view>
					</view>
					<view class="formList">
						<h1>对象:</h1>
						<view class="list" style="background: inherit; padding-left: 0;">
							<view class="duix" v-for="(item,index) in typeList" :key="index"
								:class="{'active':current==index}" @click="dianji(index)">
								{{item.name}}
								<view class="sj"><u-icon size="8" name="checkmark" color="#00132B"></u-icon></view>
							</view>
						</view>
					</view>
					<view class="formList" v-if="current==1">
						<h1>对方账号:</h1>
						<view class="list">
							<u--input border='none' v-model="in_mobile" placeholder="请输入对方账号"></u--input>
						</view>
					</view>
					<view class="formList">
						<h1>手机号:</h1>
						<view class="list">
							{{mobile}}
							<!-- <view class="code" @click="handleCode">
								{{ counting ? $t('but.againGetCode', {count}) : $t('but.getCode') }}
							</view> -->
						</view>
					</view>
					<!-- <view class="formList" style="margin-bottom: 40rpx;">
						<h1>支付密码:</h1>
						<view class="list" style="padding: 0">
							<u-code-input v-model="pwd" :space="0" color="#51E7FC" borderColor="#51E7FC" size='58'
								:maxlength="6" :dot='true'></u-code-input>

						</view>
					</view> -->
					<view class="btn-list">
						<view class="yldfotL">YLD数量：<span>{{money}}</span></view>
						<view class="yldfotR">
							<view class="btn" @click="goTransaction1">确认</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup :show="show1" mode="bottom" @close="close1" :closeable='true' :closeOnClickOverlay='true'>
			<view class="cont">
				<view class="title">复投</view>
				<view class="cent">
					<view class="formList formList1">
						<h1>易联道数量:</h1>
						<view class="list">
							<u--input border='none' v-model="Ftmoney" placeholder="请输入易联道数量"></u--input>
						</view>
					</view>
					<view class="btn-list">
						<view class="yldfotL">YLD数量：<span>{{money}}</span></view>
						<view class="yldfotR">
							<view class="btn" @click="financingFt">确认</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup :show="show2" mode="bottom" @close="close1" :closeable='true' :closeOnClickOverlay='true'
			round="16rpx">
			<view class="cont1">
				<view class="title">请输入支付密码</view>
				<view class="xy">
					<u-code-input v-model="pwd" :space="0" borderColor="#E6E6E6" size='58' :maxlength="6"
						:dot='true'></u-code-input>
				</view>
				<view class="btn-reset" @click="payBtn">支付</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				id: '',
				ids: '',
				list: {},
				ap_Yld: '',
				show: false,
				show1: false,
				show2: false,
				money: '',
				mobile: '',
				captcha: '',
				count: 60,
				counting: false,
				typeList: [{
					id: 0,
					name: '本人'
				}, {
					id: 1,
					name: '他人'
				}],
				current: 0,
				data: [],
				in_mobile: '',
				Inputmoney: '',
				Ftmoney: '',
				pwd: ''
			};
		},
		onLoad(option) {
			this.id = option.id
			this.init()
			let info = uni.getStorageSync("wanlshop:user")
			if (info.mobile == '') {
				this.mobile = uni.getStorageSync("wanlshop:user").nickname
			} else {
				this.mobile = uni.getStorageSync("wanlshop:user").mobile
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				uni.request({
					url: "/financing/financingEdit",
					method: 'POST',
					data: {
						financing_id: this.id,
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.list = res.res.data.data
							this.ap_Yld = res.res.data.ap_Yld
						}
					},
				});
				uni.request({
					url: "/financing/orderList",
					method: 'POST',
					data: {
						financing_id: this.id,
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.data = res.res.data
						}
					},
				});
			},
			// 发送手机动态码
			handleCode() {
				if (this.counting) return;
				var reg = /^1[3456789]\d{9}$/;
				if (!reg.test(this.mobile)) {
					uni.showToast({
						title: this.$t('otcTransfer.toast.auth.phone'),
						//"请输入正确的手机格式",
						icon: "none",
					});
					return;
				}
				this.getCaptcha();
			},
			// 获取验证码的接口
			getCaptcha() {
				uni.request({
					url: "/sms/send",
					method: "POST",
					data: {
						event: "mobilelogin",
						mobile: this.mobile,
					},
					success: (res) => {
						this.$wanlshop.msg(this.$t('otcTransfer.toast.getcode.success')); //"验证码发送成功"
						this.counting = true;
						const timer = setInterval(() => {
							this.count--;
							if (this.count <= 0) {
								clearInterval(timer);
								this.counting = false;
								this.count = 60; // 重置倒计时时长
							}
						}, 1000);
					},
				});
			},
			dianji(e) {
				this.current = e
			},
			//交易
			financing(val) {
				uni.request({
					url: "/financing/financingAdd",
					method: 'POST',
					data: {
						financing_id: val.id,
						money: val.money,
						type: 'all'
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.init()
							this.$wanlshop.msg(res.res.msg)
						}
					},
				});
			},

			//复投
			financingFt() {
				if (this.Ftmoney == '') {
					uni.showToast({
						title: '请输入易联道数量',
						icon: "none",
					});
					return;
				}
				uni.request({
					url: "/financing/ftzz",
					method: 'POST',
					data: {
						money: this.Ftmoney,
						financing_id: this.ids,
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.init()
							this.show1 = false
							this.$wanlshop.msg(res.res.msg)
						}
					},
				});
			},
			goTransaction1() {
				this.pwd = ''
				let mobile = ''
				if (this.Inputmoney == '') {
					uni.showToast({
						title: '请输入资产',
						icon: "none",
					});
					return;
				}
				if (this.current == 1) {
					mobile = this.in_mobile
					if (this.in_mobile == '') {
						uni.showToast({
							title: '请输入他人手机号',
							icon: "none",
						});
						return;
					}
				} else {
					mobile = this.mobile
				}
				this.show2 = true

			},
			payBtn() {
				if (this.pwd == '' || this.pwd == null) {
					uni.showToast({
						title: '请输入支付密码',
						icon: 'none'
					})
					return
				}
				if (this.pwd.length < 6) {
					uni.showToast({
						title: '请输入正确的支付密码',
						icon: 'none'
					})
					return
				}
				uni.request({
					url: "/user/getIsPayPassword",
					method: "POST",
					success: (res) => {
						if (res.res.data.pay_password_status == "yes") {
							uni.request({
								url: "/user/reyzPayPassword",
								method: "POST",
								data: {
									paypassword: this.pwd,
								},
								success: (res) => {
									if (res.res.code == 1) {
										this.show2 = false
										this.goTransaction()
									}
								},
							});
						} else {
							this.$wanlshop.auth("/pages/newPage/paypwd");
						}
					},
				});
			},
			//转账
			goTransaction() {
				let mobile = ''
				if (this.current == 1) {
					mobile = this.in_mobile
				} else {
					mobile = this.mobile
				}
				uni.request({
					url: "/user/userTransfer",
					method: 'POST',
					data: {
						in_mobile: mobile,
						// captcha: this.captcha,
						type: '13',
						money: this.Inputmoney,
						financing_id: this.ids,
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.init()
							this.show = false
							this.Inputmoney = ''
							this.in_mobile = ''
							this.captcha = ''
							this.$wanlshop.msg(res.res.msg)
						}
					},
				});

			},

			zhuanz(val) {
				this.show = true
				this.Inputmoney = ''
				this.in_mobile = ''
				this.captcha = ''
				this.ids = val.id
				uni.request({
					url: "/financing/redeem",
					method: 'POST',
					data: {
						order_id: val.id,
						ty: 'hz'
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.money = res.res.data
							// uni.reLaunch({
							// 	url: '/pages/newPage/transaction?id=1'
							// })
						}
					},
				});
			},
			fout(val) {
				this.Ftmoney = ''
				this.show1 = true
				this.ids = val.id
				uni.request({
					url: "/financing/redeem",
					method: 'POST',
					data: {
						order_id: val.id,
						ty: 'sh'
					},
					success: (res) => {
						if (res.res.code == 1) {
							this.money = res.res.data
						}
					},
				});
			},
			close() {
				this.show = false
			},
			close1() {
				this.show1 = false
				this.show2 = false
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #06224b;
	}

	.Menu {
		.yldList {
			margin: 24rpx 24rpx 16rpx 24rpx;
			background: rgba(255, 255, 255, 0.1);
			border-radius: 16rpx;
			padding: 30rpx 30rpx 30rpx 30rpx;
			font-size: 28rpx;
			height: 100%;
			overflow: auto;

			uni-view {
				color: rgba(255, 255, 255, 0.6);
				margin-bottom: 20rpx;

				h3 {
					display: inline-block;
					font-size: 32rpx;
					color: #51E7FC;

					span {
						font-size: 28rpx;
						color: #FFFFFF;
						margin-left: 20rpx;
					}
				}

				span {
					color: #FFFFFF;
				}
			}

			.btn {
				padding: 10rpx 0;
				font-size: 28rpx;
				color: #51E7FC;
				border-radius: 4rpx;
				border: 2rpx solid #51E7FC;
				max-width: 234rpx;
				text-align: center;
			}

		}

		.yldfot {
			font-size: 28rpx;
			color: #82F0FF;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.yldfotL {
				color: #fff;

				span {
					color: #51E7FC;
				}
			}

			.yldfotR {
				display: flex;
				margin-bottom: 0;

				.btn {
					width: 120rpx;
					height: 56rpx;
					line-height: 56rpx;
					text-align: center;
					border-radius: 4rpx;
					color: #012751;
					font-size: 28rpx;
					padding: 0;
				}

				.btn1 {
					color: #82F0FF;
					border-radius: 4rpx;
					border: 1px solid #51E7FC;
					margin-right: 20rpx;
				}

				.btn2 {
					background: #82F0FF;
				}
			}


		}

		.line {
			border: 1rpx dashed #51E7FC;
		}

		.cont {
			background: #00132B;

			.title {
				text-align: center;
				font-size: 28rpx;
				color: #51E7FC;
				padding: 40rpx;
			}

			.cent {
				padding: 0 24rpx;

				.formList {
					margin-bottom: 20rpx;

					h1 {
						font-weight: 400;
						font-size: 28rpx;
						color: #fff;
						line-height: 48rpx;
						margin: 20rpx 0;
						display: flex;
						align-items: center;
						justify-content: space-between;

						span {
							display: inline-block;
							padding: 4rpx 16rpx;
							background: rgba(255, 255, 255, 0.05);
							border-radius: 8rpx;
							font-size: 24rpx;
							color: #82F0FF;
						}
					}

					.list {
						background: rgba(255, 255, 255, 0.05);
						border-radius: 16rpx;
						padding: 20rpx;
						position: relative;
						display: flex;
						align-items: center;
						font-size: 28rpx;
						color: #82F0FF;
					}

					/deep/.u-input__content {


						.u-input__content__field-wrapper__field,
						.uni-input-placeholder {
							font-weight: 400;
							font-size: 28rpx !important;
							color: #82F0FF !important;
						}
					}

					.code {
						font-size: 24rpx;
						color: #82F0FF;
						position: absolute;
						right: 30rpx;
						top: 32rpx;
					}

					.duix {
						border-radius: 4rpx;
						border: 2rpx solid #51E7FC;
						opacity: 0.4;
						font-size: 28rpx;
						color: #51E7FC;
						padding: 10rpx 32rpx;
						margin-right: 40rpx;
						position: relative;

						.sj {
							position: absolute;
							right: 0;
							bottom: 0;

							/deep/.u-icon {
								position: absolute;
								left: 20px;
								transform: rotate(-90deg);
							}

						}
					}

					.active {
						opacity: 1;

						.sj {
							position: absolute;
							right: 0;
							bottom: 0;
							width: 62rpx;
							height: 62rpx;
							transform: rotate(90deg);
							background: conic-gradient(from 90deg at 50% 0, #51E7FC 0, #51E7FC 45deg, transparent 45.1deg);
						}
					}

				}

				.formList1 {
					margin-bottom: 120rpx;
					display: flex;
					align-items: center;

					h1 {
						margin-right: 20rpx;
					}

					.list {
						width: 76%;
					}
				}

				.btn-list {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-bottom: 20rpx;

					.yldfotL {
						color: #fff;

						span {
							color: #51E7FC;
						}
					}

					.yldfotR {
						display: flex;
						margin-bottom: 0;

						.btn {
							width: 260rpx;
							height: 80rpx;
							line-height: 80rpx;
							text-align: center;
							border-radius: 4rpx;
							color: #012751;
							background: #82F0FF;
							font-size: 28rpx;
							padding: 0;
						}

					}
				}
			}


		}

		/deep/.u-popup__content__close {
			.u-icon__icon {
				font-size: 40rpx !important;
				font-weight: normal !important;
				color: #51E7FC !important;
			}
		}
	}


	.cont1 {
		.title {
			font-weight: bold;
			font-size: 28rpx;
			color: #333333;
			line-height: 48rpx;
			text-align: center;
			padding: 40rpx 0;
		}

		/deep/.u-code-input {
			justify-content: center;
		}

		.xy {
			margin-bottom: 380rpx;
		}

		.btn-reset {
			width: 93%;
			height: 96rpx;
			background: #eb5641;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			font-weight: 400;
			font-size: 28rpx;
			color: #ffffff;
			line-height: 96rpx;
			margin: 0 auto 40rpx;
			text-align: center;
		}
	}
</style>